package com.originskyseed.platform.user.service.impl;

import java.util.Date;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.commons.lang3.StringUtils;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.stereotype.Component;

import com.originskyseed.platform.core.base.BasePage;
import com.originskyseed.platform.core.tenant.util.TenantCodeUtil;
import com.originskyseed.platform.core.util.bean.PrimaryKeyGeneratorUtil;
import com.originskyseed.platform.user.mapper.SpreadPlayerLimitMapper;
import com.originskyseed.platform.user.model.SpreadPlayerLimit;
import com.originskyseed.platform.user.service.ISpreadPlayerLimitService;

/**
 * 主播玩家推广上限记录表Service接口实现类（OSI_SPREAD_PLAYER_LIMIT）
 *
 * @author wlj
 */
@DubboService
@Component("spreadPlayerLimitService")
public class SpreadPlayerLimitServiceImpl implements ISpreadPlayerLimitService {

	@Resource
	private SpreadPlayerLimitMapper spreadPlayerLimitMapper;

	/**
	 * 删除记录
	 *
	 * @param id
	 * @return
	 * @throws Exception
	 */
	@Override
	public int deleteByPrimaryKey(String id) throws Exception {
		return this.spreadPlayerLimitMapper.deleteByPrimaryKey(id);
	}

	/**
	 * 批量删除记录
	 *
	 * @param ids
	 * @return
	 * @throws Exception
	 */
	@Override
	public int deleteByPrimaryKeys(List<String> ids) throws Exception {
		return this.spreadPlayerLimitMapper.deleteByPrimaryKeys(ids);
	}

	/**
	 * 插入记录
	 *
	 * @param record
	 * @return
	 * @throws Exception
	 */
	@Override
	public int insert(SpreadPlayerLimit record) throws Exception {
		if (StringUtils.isBlank(record.getId())) {
			record.setId(PrimaryKeyGeneratorUtil.getInstance().getRandomKey());
		}
		record.setCreateTime(new Date());
		return this.spreadPlayerLimitMapper.insert(record);
	}

	/**
	 * 插入记录（仅非空值字段）
	 *
	 * @param record
	 * @return
	 * @throws Exception
	 */
	@Override
	public int insertSelective(SpreadPlayerLimit record) throws Exception {
		if (StringUtils.isBlank(record.getId())) {
			record.setId(PrimaryKeyGeneratorUtil.getInstance().getRandomKey());
		}
		record.setCreateTime(new Date());
		return this.spreadPlayerLimitMapper.insertSelective(record);
	}

	/**
	 * 更新记录
	 *
	 * @param record
	 * @return
	 * @throws Exception
	 */
	@Override
	public int updateByPrimaryKey(SpreadPlayerLimit record) throws Exception {
		record.setUpdateTime(new Date());
		return this.spreadPlayerLimitMapper.updateByPrimaryKey(record);
	}

	/**
	 * 批量修改状态
	 *
	 * @param ids
	 * @param state
	 * @return
	 * @throws Exception
	 */
	@Override
	public int updateStateByIds(List<String> ids, int state) throws Exception {
		return this.spreadPlayerLimitMapper.updateStateByIds(ids, state);
	}

	/**
	 * 更新记录（仅非空值字段）
	 *
	 * @param record
	 * @return
	 * @throws Exception
	 */
	@Override
	public int updateByPrimaryKeySelective(SpreadPlayerLimit record) throws Exception {
		record.setUpdateTime(new Date());
		return this.spreadPlayerLimitMapper.updateByPrimaryKeySelective(record);
	}

	/**
	 * 查询记录
	 *
	 * @param id
	 * @return
	 * @throws Exception
	 */
	@Override
	public SpreadPlayerLimit selectByPrimaryKey(String id) throws Exception {
		return this.spreadPlayerLimitMapper.selectByPrimaryKey(id);
	}

	/**
	 * 判断数据是否已存在
	 *
	 * @param objId
	 * @return
	 * @throws Exception
	 */
	@Override
	public SpreadPlayerLimit selectIsNUllByObjId(String objId) throws Exception {
		return this.spreadPlayerLimitMapper.selectIsNUllByObjId(objId);
	}

	/**
	 * 查询记录
	 * @param objId
	 * @param tenantCode
	 * @return
	 * @throws Exception
	 */
	@Override
	public SpreadPlayerLimit selectByObjIdTenantCode(String objId, String tenantCode) throws Exception {
		if (StringUtils.isNotEmpty(tenantCode)) {
			TenantCodeUtil.getInstance().createServerTenantCode(tenantCode);
		}
		return this.selectIsNUllByObjId(objId);
	}

	/**
	 * 查询列表
	 *
	 * @param record
	 * @return
	 * @throws Exception
	 */
	@Override
	public List<SpreadPlayerLimit> selectList(SpreadPlayerLimit record) throws Exception {
		return this.spreadPlayerLimitMapper.selectList(record);
	}

	/**
	 * 分页查询列表
	 *
	 * @param params
	 * @param page
	 * @return
	 * @throws Exception
	 */
	@Override
	public BasePage<SpreadPlayerLimit> selectListByPage(Map<String, Object> params, BasePage<SpreadPlayerLimit> page) throws Exception {
		params.put("page", page);
		List<SpreadPlayerLimit> list = this.spreadPlayerLimitMapper.selectListByPage(params);
		page.setResults(list);
		return page;
	}

}
